package com.hht.baselibs.dialog

import androidx.annotation.LayoutRes
import com.hht.baselibs.util.ViewUtils


/**
 * Author:chen'hu
 * Time:2023/8/9 13:53
 * Description:This is CommonDialog
 */
class CommonDialog : BaseDialog() {
    private var convertListener: ViewConvertListener? = null

    private var onDialogDisMis: (() -> Unit)? = null

    fun setOnDialogDisMisListener(listener: (() -> Unit)) {
        onDialogDisMis = listener
    }

    companion object {
        fun newInstance(): CommonDialog {
            return CommonDialog()
        }
    }

    fun setConVertListener(listener: ViewConvertListener): BaseDialog {
        this.convertListener = listener
        return this
    }

    fun setLayoutId(@LayoutRes layoutRes: Int): CommonDialog {
        this.mLayoutResId = layoutRes
        return this
    }


    override fun getLayoutResId(): Int {
        return mLayoutResId
    }

    fun setThemeStyle(theme: Int, style: Int = STYLE_NO_TITLE): CommonDialog {
        this.setStyle(style, theme)
        return this
    }

    override fun convertView(holder: ViewUtils, dialog: BaseDialog) {
        convertListener?.apply {
            convertView(holder, dialog)
        }
    }

    interface ViewConvertListener {
        fun convertView(holder: ViewUtils, dialog: BaseDialog)
    }

    override fun dismiss() {
        super.dismiss()
        onDialogDisMis?.invoke()
    }

}